A Document Object Model (DOM) is often used to parse XML data. DOM is often implemented in XML editors to provide a programmatic representation of XML documents, fragments, nodes, or node-sets. DOM can also be used to provide an application programming interface for working with XML data. As an XML representation, DOM typically conforms to the W3C DOM standard. As a set of application programmer interfaces (APIs), XML DOM objects are usually COM objects that can expose interfaces and be used in XML applications written in programming languages such as C/C++, Visual Basic, VBScript, and JScript.
When executed, the DOM loads the entire XML document in memory and represents as a tree structure that can be accessed by the set of provided APIs. However, this parsing by DOMs is often not very efficient (especially in a server software environment) because the server often processes several files at a time and each processed file can be arbitrary long. Loading whole files that are being processed in memory can unacceptably slow down the overall performance of the server and also cause Denial of Service situations.
Another parser, SAX (Simple API for XML), is a conventional standard for event-based parsing of XML documents. SAX typically defines an abstract programmatic interface that models the XML information set (“infoset”) through a linear sequence of method calls. Although SAX and DOM are different, SAX and DOM both provide a different projection of the XML infoset onto programmatic types. Because SAX does not demand resources for an in-memory representation of the document, SAX provides a good alternative to the Document Object Model (DOM) and usually works especially well for arbitrarily large files.
SAX facilitates the search of large documents by extracting small pieces of information from a large document and allowing processing to be aborted after the information is located. However, the benefit of low memory usage requirements of SAX is offset by other disadvantages. For example, SAX often has difficulties managing context during processing when performing advanced queries.